package com.pioneer.cloudstorage.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pioneer.cloudstorage.pojo.entity.FileMetadata;
import com.pioneer.cloudstorage.pojo.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UsersMapper extends BaseMapper<User> {

    /**
     * 根据文件名搜索（模糊查询）
     */
    @Select("SELECT * FROM file_metadata WHERE user_id = #{userId} " +
            "AND file_name LIKE CONCAT('%', #{keyword}, '%') " +
            "AND status = 1 " +
            "ORDER BY updated_time DESC")
    List<FileMetadata> selectByFileName(@Param("userId") Long userId,
                                        @Param("keyword") String keyword);

    /**
     * 根据多个文件ID查询
     */
    @Select("<script>" +
            "SELECT * FROM file_metadata WHERE id IN " +
            "<foreach collection='fileIds' item='id' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            " AND status = 1" +
            "</script>")
    List<FileMetadata> selectBatchIds(@Param("fileIds") List<Long> fileIds);
}
